package net.wanho.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录拦截器
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("执行拦截器LoginInterceptor.preHandle.....................");
        /**
         * 判断是否登录
         */
        String token = request.getHeader("Authorization");
        if (token == null){
            throw new RuntimeException("请先登录再操作");
        }
        return true; // 放行
    }
}
